package com.scalar.chiptrack.operations.dataentry.actions;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.scalar.ScalarException;
import com.scalar.chiptrack.ChipTrackAction;
import com.scalar.chiptrack.commons.SessionKeys;
import com.scalar.chiptrack.operations.dataentry.dao.AssemblyDataEntryDAO;
import com.scalar.chiptrack.users.User;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: Aug 30, 2005
 * Time: 3:20:45 PM
 * To change this template use File | Settings | File Templates.
 */
public class AssemblyReleaseLotsAction extends ChipTrackAction {

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
    {
        HashMap errors  = new HashMap();
        HttpSession session = request.getSession();
        User user   = (User)session.getAttribute( SessionKeys.USER_KEY );

        if ( user == null )
        {
            request.setAttribute ( "closeWindowAfterSessionExp", "true" );
            return ( mapping.findForward( "success" ) );
        }

        String processStepIdStr= request.getParameter ( "processStepId" );
        //To fetch the Process Step Id from the format 1002/11216-01/Final Test
        StringTokenizer someValue = new StringTokenizer( processStepIdStr,"/" );
        String processStepId = someValue.nextToken();
        ArrayList lotNumbers    = null;
        try
        {
            lotNumbers = AssemblyDataEntryDAO.getAssemblyReleaseLotNumbers ( processStepId );
        }
        catch( ScalarException e )
        {
            errors.put ( "Could not get the Assembly Release Lot Numbers",null );
        }
        request.setAttribute ( "lotNumbers", lotNumbers );
        return mapping.findForward( "success" );
    }
}
